<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <base href="${pageContext.request.scheme}://${pageContext.request.serverName}:${pageContext.request.serverPort}${pageContext.request.contextPath}/">
</head>
<body>
<div id="page_nav">
    <%--页码输出的开始--%>
    <c:choose>
        <%--情况1：如果总页码小于等于5 的情况，页码的范围是：1-总页码--%>
        <c:when test="${ requestScope.page.pageTotal <= 5 }">
            <c:set var="begin" value="1" scope="page"/>
            <c:set var="end" value="${requestScope.page.pageTotal}" scope="page"/>
        </c:when>
        <%--情况2：总页码大于5 的情况--%>
        <c:when test="${requestScope.page.pageTotal > 5}">
            <c:choose>
                <%--小情况1：当前页码为前面3 个：1，2，3 的情况，页码范围是：1-5.--%>
                <c:when test="${requestScope.page.pageNo <= 3}">
                    <c:set var="begin" value="1"/>
                    <c:set var="end" value="5"/>
                </c:when>
                <%--小情况2：当前页码为最后3 个，8，9，10，页码范围是：总页码减4 - 总页码--%>
                <c:when test="${requestScope.page.pageNo > requestScope.page.pageTotal-3}">
                    <c:set var="begin" value="${requestScope.page.pageTotal-4}"/>
                    <c:set var="end" value="${requestScope.page.pageTotal}"/>
                </c:when>
                <%--小情况3：4，5，6，7，页码范围是：当前页码减2 - 当前页码加2--%>
                <c:otherwise>
                    <c:set var="begin" value="${requestScope.page.pageNo-2}"/>
                    <c:set var="end" value="${requestScope.page.pageNo+2}"/>
                </c:otherwise>
            </c:choose>
        </c:when>
    </c:choose>
    <%--页码输出的结束--%>
    <%--首页 上一页 开始 --%>
    <c:choose>
        <c:when test="${requestScope.page.pageNo>1}">
            <a href="${requestScope.page.url}&pageNo=1">首页</a>
            <a href="${requestScope.page.url}&pageNo=${requestScope.page.pageNo-1}">上一页</a>
        </c:when>
        <c:otherwise>
            <a style="color: silver">首页</a>
            <a style="color: silver">上一页</a>
        </c:otherwise>
    </c:choose>
    <%--首页 上一页 结束 --%>
    <%-- 中间页码开始 --%>
    <c:forEach begin="${begin}" end="${end}" var="i">
        <c:if test="${i == requestScope.page.pageNo}">
            【<span id="pageNo">${i}</span>】
        </c:if>
        <c:if test="${i != requestScope.page.pageNo}">
            <a href="${requestScope.page.url}&pageNo=${i}">${i}</a>
        </c:if>
    </c:forEach>
    <%-- 中间页码结束 --%>
    <%--下一页  末页 开始--%>
    <c:choose>
        <c:when test="${requestScope.page.pageNo < requestScope.page.pageTotal}">
            <a href="${requestScope.page.url}&pageNo=${requestScope.page.pageNo+1}">下一页</a>
            <a href="${requestScope.page.url}&pageNo=${requestScope.page.pageTotal}">末页</a>
        </c:when>
        <c:otherwise>
            <a style="color: silver">下一页</a>
            <a style="color: silver">末页</a>
        </c:otherwise>
    </c:choose>
    <%--下一页  末页 结束--%>
    <%-- 点跳转按钮 开始 --%>
    共${requestScope.page.pageTotal}页，${requestScope.page.pageTotalCount}条记录 到第<input name="pn" id="pn_input"/>页
    <input id="butid" type="button" value="确定">

    <script src="static/script/jquery-3.6.0.min.js"></script>
    <script>
        //输入框网页跳检查输入是不是数字
        $("#butid").click(function () {
            //获取输入框里面的值
            var pageNo = $("#pn_input").val();
            var zz2 = new RegExp("^[0-9]*[1-9][0-9]*$");
            if (zz2.test(pageNo)) {
                window.location.href = "${requestScope.page.url}&pageNo="+pageNo;
            } else {
                alert("只能输入整数")
            }
        });
    </script>
    <%-- 点跳转按钮 结束 --%>
</div>
</body>
</html>
